package org.spice.servlet.tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.DynamicAttributes;

public 
class FormTag extends BaseTag implements DynamicAttributes{

	

	private static 
	final long serialVersionUID = 1L;

	private 
	String method;

	private 
	String valueObjectBind;
	
	private 
	String action;
	
	public 
	String getAction() {
		return action;
	}
	
	public 
	void setAction(String action) {
		this.action = action;
	}
	
	public 
	String getMethod() {
		return method;
	}
	
	public 
	void setMethod(String method) {
		this.method = method;
	}
	
	public 
	String getValueObjectBind() {
		return valueObjectBind;
	}
	
	public 
	void setValueObjectBind(String valueObjectBind) {
		this.valueObjectBind = valueObjectBind;
	}
	
	
	
	@Override
	public 
	int doEndTag() throws JspException {
		try {
			this.pageContext.removeAttribute("valueObjectBind");
			this.pageContext.getOut().append("</form>");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.doEndTag();
	}
	
	
	@Override
	public 
	int doAfterBody() throws JspException {
		return super.doAfterBody();
	}
	
	
	

	@Override
	public void setDynamicAttribute(String uri, String localName, Object value)
			throws JspException {
		
	}

	@Override
	public int writeTag(PageContext pageContext) {
		try {
			this.pageContext.getOut().append("<form method=\""+getMethod()+"\" name=\""+getValueObjectBind()+"\" action=\""+getAction()+"\">");
			this.pageContext.setAttribute("valueObjectBind", getValueObjectBind());
		} catch (IOException e) {
			e.printStackTrace();
		}

		return EVAL_BODY_INCLUDE;
	}

}
